﻿using Microsoft.Kinect;
using System;

namespace KinectController
{
    internal static class KinectManager
    {
        /// <summary>
        /// Kinect sensor
        /// </summary>
        private static KinectSensor _sensor;

        public static KinectSensor KinectSensor
        {
            get
            {
                if (_sensor == null)
                {
                    foreach (var potentialSensor in KinectSensor.KinectSensors)
                    {
                        if (potentialSensor.Status == KinectStatus.Connected)
                        {
                            _sensor = potentialSensor;
                            break;
                        }
                    }
                }

                return _sensor;
            }
        }

        public static bool Start()
        {
            if (KinectSensor == null)
            {
                return false;
            }

            KinectSensor.Start();
            return true;
        }

        public static void Close()
        {
            if (KinectSensor != null)
            {
                _sensor.AudioSource.Stop();
                _sensor.Stop();
            }
        }
    }
}
